<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

    <title>cup.services package &#8212; cup 3.2.33 documentation</title>
    <link rel="stylesheet" type="text/css" href="_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="_static/alabaster.css" />
    <script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
    <script src="_static/doctools.js"></script>
    <script src="_static/sphinx_highlight.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="cup.shell package" href="cup.shell.html" />
    <link rel="prev" title="cup.res package" href="cup.res.html" />
   
  <link rel="stylesheet" href="_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <section id="module-cup.services">
<span id="cup-services-package"></span><h1>cup.services package<a class="headerlink" href="#module-cup.services" title="Permalink to this heading">¶</a></h1>
<p>&#64;author Guannan Ma &#64;mythmgn</p>
<section id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this heading">¶</a></h2>
</section>
<section id="module-cup.services.autowait">
<span id="cup-services-autowait-module"></span><h2>cup.services.autowait module<a class="headerlink" href="#module-cup.services.autowait" title="Permalink to this heading">¶</a></h2>
<dl class="field-list simple">
<dt class="field-odd">description<span class="colon">:</span></dt>
<dd class="field-odd"><p>auto wait related modules.</p>
</dd>
</dl>
<dl class="py function">
<dt class="sig sig-object py" id="cup.services.autowait.wait_until_file_exist">
<span class="sig-prename descclassname"><span class="pre">cup.services.autowait.</span></span><span class="sig-name descname"><span class="pre">wait_until_file_exist</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dst_path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">file_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_wait_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">interval_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">recursive</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/autowait.html#wait_until_file_exist"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.autowait.wait_until_file_exist" title="Permalink to this definition">¶</a></dt>
<dd><p>wait util the file exists or the function timeout</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>dst_path</strong> – searching path</p></li>
<li><p><strong>file_name</strong> – filename, support *</p></li>
<li><p><strong>max_wait_sec</strong> – max wating time until timeout</p></li>
<li><p><strong>interval_sec</strong> – check interval</p></li>
<li><p><strong>recursive</strong> – recursively search or not</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>True if found.</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="cup.services.autowait.wait_until_port_not_used">
<span class="sig-prename descclassname"><span class="pre">cup.services.autowait.</span></span><span class="sig-name descname"><span class="pre">wait_until_port_not_used</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">port</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_wait_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">interval_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.5</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/autowait.html#wait_until_port_not_used"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.autowait.wait_until_port_not_used" title="Permalink to this definition">¶</a></dt>
<dd><p>wait until the port is free</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>return True if the port is free before timeout</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="cup.services.autowait.wait_until_port_used">
<span class="sig-prename descclassname"><span class="pre">cup.services.autowait.</span></span><span class="sig-name descname"><span class="pre">wait_until_port_used</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">port</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_wait_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">interval_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.5</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/autowait.html#wait_until_port_used"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.autowait.wait_until_port_used" title="Permalink to this definition">¶</a></dt>
<dd><p>wait until the port is used.  <em>Notice this function will invoke    a bash shell to execute command [netstat]!</em></p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>return True if the port is used</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="cup.services.autowait.wait_until_process_exist">
<span class="sig-prename descclassname"><span class="pre">cup.services.autowait.</span></span><span class="sig-name descname"><span class="pre">wait_until_process_exist</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">process_path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_wait_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">interval_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.5</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/autowait.html#wait_until_process_exist"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.autowait.wait_until_process_exist" title="Permalink to this definition">¶</a></dt>
<dd><p>wait until the process exists</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>process_path</strong> – the specific process working path</p></li>
<li><p><strong>max_wait_sec</strong> – maximum waiting time until timeout</p></li>
<li><p><strong>interval_sec</strong> – state check interval</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>return True if the process is found before timeout</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="cup.services.autowait.wait_until_process_killed">
<span class="sig-prename descclassname"><span class="pre">cup.services.autowait.</span></span><span class="sig-name descname"><span class="pre">wait_until_process_killed</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">process_path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ports</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_wait_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">interval_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.5</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/autowait.html#wait_until_process_killed"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.autowait.wait_until_process_killed" title="Permalink to this definition">¶</a></dt>
<dd><p>wait until the [process] does not exists and all [ports] are free</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>process_path</strong> – process cwd</p></li>
<li><p><strong>ports</strong> – port list</p></li>
<li><p><strong>interval_sec</strong> – state check interval</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>True if all conditions meet.</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="cup.services.autowait.wait_until_process_not_exist">
<span class="sig-prename descclassname"><span class="pre">cup.services.autowait.</span></span><span class="sig-name descname"><span class="pre">wait_until_process_not_exist</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">process_path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_wait_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">interval_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.5</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/autowait.html#wait_until_process_not_exist"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.autowait.wait_until_process_not_exist" title="Permalink to this definition">¶</a></dt>
<dd><p>wait until the process does not exist anymore or the function timeouts</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>process_path</strong> – process cwd</p></li>
<li><p><strong>max_wait_sec</strong> – maximum waiting time until timeout. 10 seconds by default</p></li>
<li><p><strong>interval_sec</strong> – state check interval, 0.5 second by default</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>return True if the process disapper before timeout</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="cup.services.autowait.wait_until_process_used_ports">
<span class="sig-prename descclassname"><span class="pre">cup.services.autowait.</span></span><span class="sig-name descname"><span class="pre">wait_until_process_used_ports</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">process_path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ports</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_wait_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">interval_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.5</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/autowait.html#wait_until_process_used_ports"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.autowait.wait_until_process_used_ports" title="Permalink to this definition">¶</a></dt>
<dd><p>wait until the process has taken the ports before timeouts</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>True if all ports are used by the specific process.
False, otherwise</p>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="cup.services.autowait.wait_until_reg_str_exist">
<span class="sig-prename descclassname"><span class="pre">cup.services.autowait.</span></span><span class="sig-name descname"><span class="pre">wait_until_reg_str_exist</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dst_file_path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reg_str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_wait_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">interval_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.5</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/autowait.html#wait_until_reg_str_exist"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.autowait.wait_until_reg_str_exist" title="Permalink to this definition">¶</a></dt>
<dd><p>wait until any line in the file matches the     reg_str(regular expression string)</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>dst_file_path</strong> – searching path</p></li>
<li><p><strong>reg_str</strong> – regular expression string</p></li>
<li><p><strong>max_wait_sec</strong> – maximum waiting time until timeout</p></li>
<li><p><strong>interval_sec</strong> – state check interval</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>True if found</p>
</dd>
</dl>
</dd></dl>

</section>
<section id="module-cup.services.buffers">
<span id="cup-services-buffers-module"></span><h2>cup.services.buffers module<a class="headerlink" href="#module-cup.services.buffers" title="Permalink to this heading">¶</a></h2>
<dl class="field-list simple">
<dt class="field-odd">description<span class="colon">:</span></dt>
<dd class="field-odd"><p>buffer pool</p>
</dd>
</dl>
<dl class="py class">
<dt class="sig sig-object py" id="cup.services.buffers.Buffer">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.buffers.</span></span><span class="sig-name descname"><span class="pre">Buffer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">items</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">block_size</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">uniqid</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/buffers.html#Buffer"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.buffers.Buffer" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Buffer object which you get from BufferPool.allocate(num).</p>
<p>A <strong>Buffer</strong> consists of several bytearrays which is mutable compared to
a normal <strong>str</strong>. In other words, if you have senarios like: allocte mem
and deallocte mem frenquently. With high chance you can replace directly
using str by Buffer. It will reduce the memory fragments.</p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.buffers.Buffer.get">
<span class="sig-name descname"><span class="pre">get</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/buffers.html#Buffer.get"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.buffers.Buffer.get" title="Permalink to this definition">¶</a></dt>
<dd><p>return (True, (blocks, block_size, total_length, encoding)) if succeed</p>
<p>Otherwise, return (False, err_msg, None)</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.buffers.Buffer.get_byte_arrays">
<span class="sig-name descname"><span class="pre">get_byte_arrays</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/buffers.html#Buffer.get_byte_arrays"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.buffers.Buffer.get_byte_arrays" title="Permalink to this definition">¶</a></dt>
<dd><p>get byte arrays in the buffer</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.buffers.Buffer.get_uniq_id">
<span class="sig-name descname"><span class="pre">get_uniq_id</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/buffers.html#Buffer.get_uniq_id"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.buffers.Buffer.get_uniq_id" title="Permalink to this definition">¶</a></dt>
<dd><p>return the uniqid for this object</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.buffers.Buffer.length">
<span class="sig-name descname"><span class="pre">length</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/buffers.html#Buffer.length"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.buffers.Buffer.length" title="Permalink to this definition">¶</a></dt>
<dd><p>return the length you have used for the buffer</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.buffers.Buffer.maxsize">
<span class="sig-name descname"><span class="pre">maxsize</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/buffers.html#Buffer.maxsize"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.buffers.Buffer.maxsize" title="Permalink to this definition">¶</a></dt>
<dd><p>return how many unicode/str you can set to the buffer</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.buffers.Buffer.set">
<span class="sig-name descname"><span class="pre">set</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">content</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'utf8'</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/buffers.html#Buffer.set"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.buffers.Buffer.set" title="Permalink to this definition">¶</a></dt>
<dd><p>set content to buffers</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>return (True, None) if succeed.
return (False, error_msg) otherwise</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="cup.services.buffers.BufferPool">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.buffers.</span></span><span class="sig-name descname"><span class="pre">BufferPool</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">pool_size</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">block_size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">135168</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">extendable</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/buffers.html#BufferPool"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.buffers.BufferPool" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Buffer pool class which will ease memory fragment.</p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.buffers.BufferPool.allocate">
<span class="sig-name descname"><span class="pre">allocate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">num</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/buffers.html#BufferPool.allocate"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.buffers.BufferPool.allocate" title="Permalink to this definition">¶</a></dt>
<dd><p>acclocate buff with num * block_size</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p><p>(True, Buffer object)</p>
<p>(False, str_error_msg)</p>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.buffers.BufferPool.deallocate">
<span class="sig-name descname"><span class="pre">deallocate</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">buff</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/buffers.html#BufferPool.deallocate"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.buffers.BufferPool.deallocate" title="Permalink to this definition">¶</a></dt>
<dd><p>return the acclocated buff back to the pool</p>
</dd></dl>

</dd></dl>

</section>
<section id="module-cup.services.executor">
<span id="cup-services-executor-module"></span><h2>cup.services.executor module<a class="headerlink" href="#module-cup.services.executor" title="Permalink to this heading">¶</a></h2>
<dl class="field-list simple">
<dt class="field-odd">description<span class="colon">:</span></dt>
<dd class="field-odd"><ol class="arabic simple">
<li><p>Delay-execute sth after several seconds</p></li>
<li><p>Schedule some tasks in a queue.</p></li>
</ol>
</dd>
</dl>
<dl class="py class">
<dt class="sig sig-object py" id="cup.services.executor.AbstractExecution">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.executor.</span></span><span class="sig-name descname"><span class="pre">AbstractExecution</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">delay_exe_thdnum</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">queue_exec_thdnum</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#AbstractExecution"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.AbstractExecution" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>abstract execution service</p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.AbstractExecution.delay_exec">
<em class="property"><span class="pre">abstract</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">delay_exec</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">delay_time_insec</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">urgency</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#AbstractExecution.delay_exec"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.AbstractExecution.delay_exec" title="Permalink to this definition">¶</a></dt>
<dd><p>delay exec for the abstract</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.AbstractExecution.exec_worker">
<em class="property"><span class="pre">abstract</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">exec_worker</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">check_interval</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">func_queue</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">worker_name</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#AbstractExecution.exec_worker"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.AbstractExecution.exec_worker" title="Permalink to this definition">¶</a></dt>
<dd><p>exec worker</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="cup.services.executor.CronExecution">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.executor.</span></span><span class="sig-name descname"><span class="pre">CronExecution</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">threads_num</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">3</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronExecution"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronExecution" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.services.executor.ExecutionService" title="cup.services.executor.ExecutionService"><code class="xref py py-class docutils literal notranslate"><span class="pre">ExecutionService</span></code></a></p>
<p>run execution like cron.</p>
<dl class="simple">
<dt>Plz notice the following circumstances:</dt><dd><ul class="simple">
<li><dl class="simple">
<dt>if the previous task is still running and the scheduing time comes,</dt><dd><p>executor will wait until the previous task finishes</p>
</dd>
</dl>
</li>
</ul>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronExecution.calcel_delay_exec">
<span class="sig-name descname"><span class="pre">calcel_delay_exec</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">taskid</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronExecution.calcel_delay_exec"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronExecution.calcel_delay_exec" title="Permalink to this definition">¶</a></dt>
<dd><p>calcel delayexec by taskid</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronExecution.delay_exec">
<span class="sig-name descname"><span class="pre">delay_exec</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">delay_time_insec</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">crontask</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">urgency</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronExecution.delay_exec"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronExecution.delay_exec" title="Permalink to this definition">¶</a></dt>
<dd><p>delay_execute function after delay_time seconds</p>
<p>You can use urgency := executor.URGENCY_NORMAL, by default</p>
<dl class="field-list simple">
<dt class="field-odd">TODO<span class="colon">:</span></dt>
<dd class="field-odd"><p>consider about stopping timers when invoking stop function</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronExecution.exec_worker">
<span class="sig-name descname"><span class="pre">exec_worker</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">check_interval</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">func_queue</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">worker_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronExecution.exec_worker"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronExecution.exec_worker" title="Permalink to this definition">¶</a></dt>
<dd><p>exec worker</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronExecution.get_taskbyid">
<span class="sig-name descname"><span class="pre">get_taskbyid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">md5uuid</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronExecution.get_taskbyid"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronExecution.get_taskbyid" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>md5uuid</strong> – md5sum of uuid</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronExecution.get_tasks">
<span class="sig-name descname"><span class="pre">get_tasks</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronExecution.get_tasks"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronExecution.get_tasks" title="Permalink to this definition">¶</a></dt>
<dd><p>get all cron execution tasks</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronExecution.schedule">
<span class="sig-name descname"><span class="pre">schedule</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">crontask</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronExecution.schedule"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronExecution.schedule" title="Permalink to this definition">¶</a></dt>
<dd><p>schedule the crontask</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>timer_dict</strong> – <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>   <span class="s1">&#39;minute&#39;</span><span class="p">:</span> <span class="n">minute_list</span><span class="p">,</span>
    <span class="s1">&#39;hour&#39;</span><span class="p">:</span> <span class="n">hour_list</span><span class="p">,</span>
    <span class="s1">&#39;weekday&#39;</span><span class="p">:</span> <span class="n">weekday_list</span><span class="p">,</span>
    <span class="s1">&#39;monthday&#39;</span><span class="p">:</span> <span class="n">monday_list</span><span class="p">,</span>
    <span class="s1">&#39;month&#39;</span><span class="p">:</span> <span class="n">month_list</span>
<span class="p">}</span>
</pre></div>
</div>
</p></li>
<li><p><strong>function</strong> – function that to be scheduled</p></li>
<li><p><strong>args</strong> – args of function</p></li>
<li><p><strong>kwargs</strong> – key args of function</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="cup.services.executor.CronTask">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.executor.</span></span><span class="sig-name descname"><span class="pre">CronTask</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pytz_timezone</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timer_dict</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">md5uuid</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>crontask for CronExecution</p>
<p>Typical exmaples for timer_dict:</p>
<p>1. one specific time  Jan 1st, 2020 18:01</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">timer_dict</span> <span class="p">{</span>
    <span class="s1">&#39;minute&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="s1">&#39;hour&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">18</span><span class="p">],</span> <span class="s1">&#39;weekday&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
    <span class="s1">&#39;monthday&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="s1">&#39;month&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="p">}</span>
</pre></div>
</div>
<p>2. every minute {</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">timer_dict</span> <span class="p">{</span>
        <span class="s1">&#39;minute&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="o">...</span><span class="mf">.59</span><span class="p">],</span> <span class="s1">&#39;hour&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;weekday&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
        <span class="s1">&#39;monthday&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;month&#39;</span><span class="p">:</span> <span class="kc">None</span>
<span class="p">}</span>
</pre></div>
</div>
<p>3. every hour</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">timer_dict</span> <span class="p">{</span>
        <span class="s1">&#39;minute&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;hour&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;weekday&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
        <span class="s1">&#39;monthday&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;month&#39;</span><span class="p">:</span> <span class="kc">None</span>
<span class="p">}</span>
</pre></div>
</div>
<p>4. every 20:00 PM</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">timer_dict</span> <span class="p">{</span>
    <span class="s1">&#39;minute&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;hour&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">20</span><span class="p">],</span> <span class="s1">&#39;weekday&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
    <span class="s1">&#39;monthday&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;month&#39;</span><span class="p">:</span> <span class="kc">None</span>
<span class="p">}</span>
</pre></div>
</div>
<p>5. every 20:00 PM at workdays (Monday to Friday)</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">timer_dict</span> <span class="p">{</span>
        <span class="s1">&#39;minute&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;hour&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">20</span><span class="p">],</span> <span class="s1">&#39;weekday&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span>
        <span class="s1">&#39;monthday&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;month&#39;</span><span class="p">:</span> <span class="kc">None</span>
<span class="p">}</span>
</pre></div>
</div>
<p>6. every 20:00 PM at workdays for Jan and July</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">timer_dict</span> <span class="p">{</span>
    <span class="s1">&#39;minute&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;hour&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">20</span><span class="p">],</span> <span class="s1">&#39;weekday&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span>
    <span class="s1">&#39;monthday&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span> <span class="s1">&#39;month&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">7</span><span class="p">]</span>
<span class="p">}</span>
</pre></div>
</div>
<p>7. every 20:00 PM at 1st, 3rd of Jan and July</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">timer_dict</span> <span class="p">{</span>
    <span class="s1">&#39;minute&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s1">&#39;hour&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">20</span><span class="p">],</span> <span class="s1">&#39;weekday&#39;</span><span class="p">:</span> <span class="kc">None</span><span class="p">,</span>
    <span class="s1">&#39;monthday&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="s1">&#39;month&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">7</span><span class="p">]</span>
<span class="p">}</span>
</pre></div>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.check_monthday_weekday">
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">check_monthday_weekday</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tmp_dict</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timer_params</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.check_monthday_weekday"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.check_monthday_weekday" title="Permalink to this definition">¶</a></dt>
<dd><p>check if monthday / weekday valid</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.get_funcargs">
<span class="sig-name descname"><span class="pre">get_funcargs</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.get_funcargs"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.get_funcargs" title="Permalink to this definition">¶</a></dt>
<dd><p>return (function, args, kwargs)</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.get_last_schedtime">
<span class="sig-name descname"><span class="pre">get_last_schedtime</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.get_last_schedtime"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.get_last_schedtime" title="Permalink to this definition">¶</a></dt>
<dd><p>get last sched time, return with a datetime.datetime object.
Plz notice the timezone is enabled</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.get_timer">
<span class="sig-name descname"><span class="pre">get_timer</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.get_timer"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.get_timer" title="Permalink to this definition">¶</a></dt>
<dd><p>return timer of the crontask</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.last_schedtime">
<span class="sig-name descname"><span class="pre">last_schedtime</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.last_schedtime"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.last_schedtime" title="Permalink to this definition">¶</a></dt>
<dd><p>return last schedtime</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.name">
<span class="sig-name descname"><span class="pre">name</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.name"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.name" title="Permalink to this definition">¶</a></dt>
<dd><p>return name of the crontask</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.next_hour">
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">next_hour</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tmp_dict</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timer_params</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.next_hour"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.next_hour" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p><dl class="simple">
<dt>{ ‘year’: xxx,</dt><dd><p>’month’: xxx,
‘monthday’:</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.next_minute">
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">next_minute</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tmp_dict</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timer_params</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.next_minute"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.next_minute" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p><dl class="simple">
<dt>{ ‘year’: xxx,</dt><dd><p>’month’: xxx,
‘monthday’:</p>
</dd>
</dl>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.next_month">
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">next_month</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tmp_dict</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timer_params</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.next_month"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.next_month" title="Permalink to this definition">¶</a></dt>
<dd><p>set tmp_dict to next valid date, specifically month</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>tmp_dict</strong> – <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
    <span class="s1">&#39;year&#39;</span><span class="p">:</span> <span class="n">xxxx</span><span class="p">,</span>
    <span class="s1">&#39;month&#39;</span><span class="p">:</span> <span class="n">xxxx</span><span class="p">,</span>
    <span class="s1">&#39;monthday&#39;</span><span class="p">:</span> <span class="n">xxxx</span><span class="p">,</span>
    <span class="s1">&#39;weekday&#39;</span><span class="p">:</span> <span class="n">xxxx</span><span class="p">,</span>
    <span class="s1">&#39;hour&#39;</span><span class="p">:</span> <span class="n">xxxx</span><span class="p">,</span>
    <span class="s1">&#39;minute&#39;</span><span class="p">:</span> <span class="n">xxxx</span>
<span class="p">}</span>
</pre></div>
</div>
</p></li>
<li><p><strong>timer_params</strong> – valid timer dict, same to self._timer_params</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.next_monthday_weekday">
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">next_monthday_weekday</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tmp_dict</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">timer_params</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.next_monthday_weekday"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.next_monthday_weekday" title="Permalink to this definition">¶</a></dt>
<dd><p>set next monthday &amp;&amp; weekday</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.next_schedtime">
<span class="sig-name descname"><span class="pre">next_schedtime</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">starting_fromdate</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.next_schedtime"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.next_schedtime" title="Permalink to this definition">¶</a></dt>
<dd><p>return next schedule time with timezone enabled.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.pytz_timezone">
<span class="sig-name descname"><span class="pre">pytz_timezone</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.pytz_timezone"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.pytz_timezone" title="Permalink to this definition">¶</a></dt>
<dd><p>return pytz timezone</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.set_last_schedtime">
<span class="sig-name descname"><span class="pre">set_last_schedtime</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">datetime_obj</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.set_last_schedtime"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.set_last_schedtime" title="Permalink to this definition">¶</a></dt>
<dd><p>set_last_schedtime.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>timestamp</strong> – E.g. set timestamp to time.time() for “now”</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.set_timer">
<span class="sig-name descname"><span class="pre">set_timer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">timer</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.set_timer"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.set_timer" title="Permalink to this definition">¶</a></dt>
<dd><p>set timer to this crontask</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.CronTask.taskid">
<span class="sig-name descname"><span class="pre">taskid</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#CronTask.taskid"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.CronTask.taskid" title="Permalink to this definition">¶</a></dt>
<dd><p>get 32 byte taskid</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="cup.services.executor.ExecutionService">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.executor.</span></span><span class="sig-name descname"><span class="pre">ExecutionService</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">delay_exe_thdnum</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">3</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">queue_exec_thdnum</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">4</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#ExecutionService"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.ExecutionService" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.services.executor.AbstractExecution" title="cup.services.executor.AbstractExecution"><code class="xref py py-class docutils literal notranslate"><span class="pre">AbstractExecution</span></code></a></p>
<p>execution service</p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.ExecutionService.delay_exec">
<span class="sig-name descname"><span class="pre">delay_exec</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">delay_time_insec</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">urgency</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#ExecutionService.delay_exec"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.ExecutionService.delay_exec" title="Permalink to this definition">¶</a></dt>
<dd><p>delay_execute function after delay_time seconds</p>
<p>You can use urgency := executor.URGENCY_NORMAL, by default</p>
<dl class="field-list simple">
<dt class="field-odd">TODO<span class="colon">:</span></dt>
<dd class="field-odd"><p>consider about stopping timers when invoking stop function</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.ExecutionService.exec_worker">
<span class="sig-name descname"><span class="pre">exec_worker</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">check_interval</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">func_queue</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">worker_name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">''</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#ExecutionService.exec_worker"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.ExecutionService.exec_worker" title="Permalink to this definition">¶</a></dt>
<dd><p>exec worker</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.ExecutionService.queue_exec">
<span class="sig-name descname"><span class="pre">queue_exec</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">function</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">urgency</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">argvs</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#ExecutionService.queue_exec"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.ExecutionService.queue_exec" title="Permalink to this definition">¶</a></dt>
<dd><p>execute function in a queue. Functions will be queued in line to
be scheduled.</p>
<p>You can use urgency := executor.URGENCY_NORMAL, by default.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.ExecutionService.run">
<span class="sig-name descname"><span class="pre">run</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#ExecutionService.run"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.ExecutionService.run" title="Permalink to this definition">¶</a></dt>
<dd><p>Delayexec worker checks task every 20ms
QueueExec worker checks task every 100ms</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.ExecutionService.start">
<span class="sig-name descname"><span class="pre">start</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#ExecutionService.start"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.ExecutionService.start" title="Permalink to this definition">¶</a></dt>
<dd><p>alias for self.run</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.executor.ExecutionService.stop">
<span class="sig-name descname"><span class="pre">stop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">wait_workerstop</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/executor.html#ExecutionService.stop"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.executor.ExecutionService.stop" title="Permalink to this definition">¶</a></dt>
<dd><p>stop the executor service.</p>
<dl class="field-list">
<dt class="field-odd">Wait_workerstop<span class="colon">:</span></dt>
<dd class="field-odd"><p>If wait_workerstop is True, the function will hang util all workers
finish thier tasks.</p>
<p>Otherwise, the function will not hang, but tell you whether it’s
succeeded stopped. (True for stoped, False for not stopped yet)</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</section>
<section id="module-cup.services.generator">
<span id="cup-services-generator-module"></span><h2>cup.services.generator module<a class="headerlink" href="#module-cup.services.generator" title="Permalink to this heading">¶</a></h2>
<section id="class-cgeneratorman-object">
<h3>class CGeneratorMan(object)<a class="headerlink" href="#class-cgeneratorman-object" title="Permalink to this heading">¶</a></h3>
<p>Generate unique integers, strings and auto incremental uint.
Notice CGeneratorMan is a singleton class, which means cup will keep
only 1 instance per process.</p>
<dl class="field-list simple">
<dt class="field-odd">init<span class="colon">:</span></dt>
<dd class="field-odd"><dl class="simple">
<dt>__init__(self, str_prefix=get_local_hostname())</dt><dd><p>local hostname will be used by default.</p>
</dd>
</dl>
</dd>
<dt class="field-even">methods<span class="colon">:</span></dt>
<dd class="field-even"><dl class="simple">
<dt><strong>get_uniqname()</strong></dt><dd><p>get unique name.
Host-Level unique name (build upon str_prefix, pid, threadid)</p>
</dd>
<dt><strong>get_next_uniq_num()</strong></dt><dd><p>Process-level auto incremental uint. Thread-safe</p>
</dd>
<dt><strong>reset_uniqid_start(num=0)</strong></dt><dd><p>Reset next uniqid to which genman starts from</p>
</dd>
<dt><strong>get_random_str()</strong></dt><dd><p>Get random string by length</p>
</dd>
<dt><strong>get_uuid()</strong></dt><dd><p>Get uuid</p>
</dd>
</dl>
</dd>
</dl>
</section>
<dl class="py class">
<dt class="sig sig-object py" id="cup.services.generator.CycleIDGenerator">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.generator.</span></span><span class="sig-name descname"><span class="pre">CycleIDGenerator</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ip</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">port</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/generator.html#CycleIDGenerator"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.generator.CycleIDGenerator" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>cycle id generator. 128bit ID will be produced.</p>
<p>128 bit contains: a. 64bit [ip, port, etc]  b. 64bit[auto increment id]</p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.generator.CycleIDGenerator.id2_hexstring">
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">id2_hexstring</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">num</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/generator.html#CycleIDGenerator.id2_hexstring"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.generator.CycleIDGenerator.id2_hexstring" title="Permalink to this definition">¶</a></dt>
<dd><p>return hex of the id</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.generator.CycleIDGenerator.next_id">
<span class="sig-name descname"><span class="pre">next_id</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/generator.html#CycleIDGenerator.next_id"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.generator.CycleIDGenerator.next_id" title="Permalink to this definition">¶</a></dt>
<dd><p>get next id</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.generator.CycleIDGenerator.reset_nextid">
<span class="sig-name descname"><span class="pre">reset_nextid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">nextid</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/generator.html#CycleIDGenerator.reset_nextid"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.generator.CycleIDGenerator.reset_nextid" title="Permalink to this definition">¶</a></dt>
<dd><p>reset nextid that will return to you</p>
</dd></dl>

</dd></dl>

</section>
<section id="module-cup.services.heartbeat">
<span id="cup-services-heartbeat-module"></span><h2>cup.services.heartbeat module<a class="headerlink" href="#module-cup.services.heartbeat" title="Permalink to this heading">¶</a></h2>
<dl class="field-list simple">
<dt class="field-odd">description<span class="colon">:</span></dt>
<dd class="field-odd"><p>heartbeat related module</p>
</dd>
</dl>
<dl class="py class">
<dt class="sig sig-object py" id="cup.services.heartbeat.Device">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.heartbeat.</span></span><span class="sig-name descname"><span class="pre">Device</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#Device"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.Device" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Base class for all devices in heartbeat service</p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.Device.deserilize">
<span class="sig-name descname"><span class="pre">deserilize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">binary</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#Device.deserilize"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.Device.deserilize" title="Permalink to this definition">¶</a></dt>
<dd><p>deserilize it from binary</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.Device.get_dict_resinfo">
<span class="sig-name descname"><span class="pre">get_dict_resinfo</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#Device.get_dict_resinfo"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.Device.get_dict_resinfo" title="Permalink to this definition">¶</a></dt>
<dd><p>get dict of resource info</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.Device.get_last_healthy">
<span class="sig-name descname"><span class="pre">get_last_healthy</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#Device.get_last_healthy"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.Device.get_last_healthy" title="Permalink to this definition">¶</a></dt>
<dd><p>get last_healthy time of the device</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.Device.get_name">
<span class="sig-name descname"><span class="pre">get_name</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#Device.get_name"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.Device.get_name" title="Permalink to this definition">¶</a></dt>
<dd><p>get name</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.Device.serilize">
<span class="sig-name descname"><span class="pre">serilize</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#Device.serilize"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.Device.serilize" title="Permalink to this definition">¶</a></dt>
<dd><p>serilize device info</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.Device.set_last_healthy">
<span class="sig-name descname"><span class="pre">set_last_healthy</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#Device.set_last_healthy"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.Device.set_last_healthy" title="Permalink to this definition">¶</a></dt>
<dd><p>set last_healthy time</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="cup.services.heartbeat.HeartbeatService">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.heartbeat.</span></span><span class="sig-name descname"><span class="pre">HeartbeatService</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">judge_lost_in_sec</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">keep_lost</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#HeartbeatService"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.HeartbeatService" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>HeartBeat service</p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.HeartbeatService.adjust_judge_lost_time">
<span class="sig-name descname"><span class="pre">adjust_judge_lost_time</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">time_in_sec</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#HeartbeatService.adjust_judge_lost_time"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.HeartbeatService.adjust_judge_lost_time" title="Permalink to this definition">¶</a></dt>
<dd><p>adjust judge_lost_in_sec</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.HeartbeatService.cleanup_oldlost">
<span class="sig-name descname"><span class="pre">cleanup_oldlost</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dump_file</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#HeartbeatService.cleanup_oldlost"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.HeartbeatService.cleanup_oldlost" title="Permalink to this definition">¶</a></dt>
<dd><p>cleanup old lost devices.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>dump_file</strong> – if dump_file is not None, we will store devices info into dump_file
Otherwise, we will cleanup the lost devices only.</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.HeartbeatService.get_lost">
<span class="sig-name descname"><span class="pre">get_lost</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#HeartbeatService.get_lost"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.HeartbeatService.get_lost" title="Permalink to this definition">¶</a></dt>
<dd><p>get lost devices</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.HeartbeatService.is_device_registered">
<span class="sig-name descname"><span class="pre">is_device_registered</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">including_dead</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#HeartbeatService.is_device_registered"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.HeartbeatService.is_device_registered" title="Permalink to this definition">¶</a></dt>
<dd><p>tell if the device is registered</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.HeartbeatService.refresh">
<span class="sig-name descname"><span class="pre">refresh</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">device_obj</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#HeartbeatService.refresh"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.HeartbeatService.refresh" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>key</strong> – refresh the device by key</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>if key does not exist, return False
else, fresh the last_healthy time of the device</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="cup.services.heartbeat.LinuxHost">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.heartbeat.</span></span><span class="sig-name descname"><span class="pre">LinuxHost</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">init_this_host</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">iface</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'eth0'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">port</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#LinuxHost"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.LinuxHost" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.services.heartbeat.Device" title="cup.services.heartbeat.Device"><code class="xref py py-class docutils literal notranslate"><span class="pre">Device</span></code></a></p>
<p>a linux host resource</p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.LinuxHost.get_cpu_idle">
<span class="sig-name descname"><span class="pre">get_cpu_idle</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#LinuxHost.get_cpu_idle"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.LinuxHost.get_cpu_idle" title="Permalink to this definition">¶</a></dt>
<dd><p>get cpu idle rate</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.LinuxHost.get_ip">
<span class="sig-name descname"><span class="pre">get_ip</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#LinuxHost.get_ip"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.LinuxHost.get_ip" title="Permalink to this definition">¶</a></dt>
<dd><p>return ip information</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.LinuxHost.get_ip_port">
<span class="sig-name descname"><span class="pre">get_ip_port</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#LinuxHost.get_ip_port"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.LinuxHost.get_ip_port" title="Permalink to this definition">¶</a></dt>
<dd><p>return ip:port</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.LinuxHost.get_mem_info">
<span class="sig-name descname"><span class="pre">get_mem_info</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#LinuxHost.get_mem_info"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.LinuxHost.get_mem_info" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>(mem_inuse, mem_total), in MB</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.LinuxHost.get_net_usage">
<span class="sig-name descname"><span class="pre">get_net_usage</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#LinuxHost.get_net_usage"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.LinuxHost.get_net_usage" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>(net_in, net_out)</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.LinuxHost.set_cpu_idle">
<span class="sig-name descname"><span class="pre">set_cpu_idle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">idle_rate</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#LinuxHost.set_cpu_idle"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.LinuxHost.set_cpu_idle" title="Permalink to this definition">¶</a></dt>
<dd><p>set cpu idle rate</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.LinuxHost.set_ip_port">
<span class="sig-name descname"><span class="pre">set_ip_port</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ipaddr</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#LinuxHost.set_ip_port"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.LinuxHost.set_ip_port" title="Permalink to this definition">¶</a></dt>
<dd><p>set ip information</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>ipaddr</strong> – ipaddr should be string and something like 10.10.10.1</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.LinuxHost.set_linux_res_bydict">
<span class="sig-name descname"><span class="pre">set_linux_res_bydict</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">info_dict</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#LinuxHost.set_linux_res_bydict"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.LinuxHost.set_linux_res_bydict" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>info_dict</strong> – <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
    <span class="s1">&#39;iface&#39;</span><span class="p">:</span> <span class="s1">&#39;eth0&#39;</span><span class="p">,</span>
    <span class="s1">&#39;ipaddr&#39;</span><span class="p">:</span> <span class="s1">&#39;10.10.10.1&#39;</span><span class="p">,</span>
    <span class="s1">&#39;port&#39;</span><span class="p">:</span>   <span class="mi">8089</span><span class="p">,</span>
    <span class="s1">&#39;cpu_idle&#39;</span><span class="p">:</span> <span class="mi">50</span><span class="p">,</span>
    <span class="s1">&#39;mem_inuse&#39;</span><span class="p">:</span> <span class="mi">1024</span><span class="p">,</span>        <span class="c1"># MB</span>
    <span class="s1">&#39;mem_total&#39;</span><span class="p">:</span> <span class="mi">8192</span><span class="p">,</span>
    <span class="s1">&#39;net_in&#39;</span><span class="p">:</span>    <span class="mi">8192</span><span class="p">,</span>        <span class="c1"># kb</span>
    <span class="s1">&#39;net_out&#39;</span><span class="p">:</span>   <span class="mi">102400</span><span class="p">,</span>      <span class="c1"># kb</span>
<span class="p">}</span>
</pre></div>
</div>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.LinuxHost.set_mem_usage">
<span class="sig-name descname"><span class="pre">set_mem_usage</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">mem_inuse</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mem_total</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#LinuxHost.set_mem_usage"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.LinuxHost.set_mem_usage" title="Permalink to this definition">¶</a></dt>
<dd><p>set up mem_inuse and mem_total.
Will update any of them if it is not None.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.LinuxHost.set_net_usage">
<span class="sig-name descname"><span class="pre">set_net_usage</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">net_in</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">net_out</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#LinuxHost.set_net_usage"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.LinuxHost.set_net_usage" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>net_in</strong> – net_in in kB/s. If net_in is None, will update nothing.</p></li>
<li><p><strong>net_out</strong> – net_out in kB/s. If net_out is None, will update nothing.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="cup.services.heartbeat.MacHost">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.heartbeat.</span></span><span class="sig-name descname"><span class="pre">MacHost</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">init_this_host</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">iface</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'en01'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">port</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#MacHost"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.MacHost" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.services.heartbeat.Device" title="cup.services.heartbeat.Device"><code class="xref py py-class docutils literal notranslate"><span class="pre">Device</span></code></a></p>
<p>a mac host</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="cup.services.heartbeat.RestrictedUnpickler">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.heartbeat.</span></span><span class="sig-name descname"><span class="pre">RestrictedUnpickler</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">fix_imports</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">encoding</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'ASCII'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">errors</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'strict'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">buffers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">()</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#RestrictedUnpickler"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.RestrictedUnpickler" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">Unpickler</span></code></p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.heartbeat.RestrictedUnpickler.find_class">
<span class="sig-name descname"><span class="pre">find_class</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">module</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#RestrictedUnpickler.find_class"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.RestrictedUnpickler.find_class" title="Permalink to this definition">¶</a></dt>
<dd><p>Only allow safe classes from builtins</p>
<p>Only check builtins when it’s run under py 3</p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="cup.services.heartbeat.restricted_loads">
<span class="sig-prename descclassname"><span class="pre">cup.services.heartbeat.</span></span><span class="sig-name descname"><span class="pre">restricted_loads</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/heartbeat.html#restricted_loads"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.heartbeat.restricted_loads" title="Permalink to this definition">¶</a></dt>
<dd><p>Helper function analogous to pickle.loads()</p>
</dd></dl>

</section>
<section id="module-cup.services.msgbroker">
<span id="cup-services-msgbroker-module"></span><h2>cup.services.msgbroker module<a class="headerlink" href="#module-cup.services.msgbroker" title="Permalink to this heading">¶</a></h2>
<dl class="field-list">
<dt class="field-odd">description<span class="colon">:</span></dt>
<dd class="field-odd"><p>Msg Broker Service. Every component of a process can produce_msg.</p>
<p>This msg broker feature is still exprimental. Do not use it in production
until this comment is deleted.</p>
</dd>
</dl>
<dl class="py class">
<dt class="sig sig-object py" id="cup.services.msgbroker.BrokerCenter">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.msgbroker.</span></span><span class="sig-name descname"><span class="pre">BrokerCenter</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/msgbroker.html#BrokerCenter"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.msgbroker.BrokerCenter" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">BaseBroker</span></code></p>
<p>Errmsg broker center</p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.msgbroker.BrokerCenter.comsume_msg">
<span class="sig-name descname"><span class="pre">comsume_msg</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg_type</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/msgbroker.html#BrokerCenter.comsume_msg"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.msgbroker.BrokerCenter.comsume_msg" title="Permalink to this definition">¶</a></dt>
<dd><p>get msg_type from the broker center</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.msgbroker.BrokerCenter.produce_msg">
<span class="sig-name descname"><span class="pre">produce_msg</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">msg_type</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">extra_info</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">error</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/msgbroker.html#BrokerCenter.produce_msg"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.msgbroker.BrokerCenter.produce_msg" title="Permalink to this definition">¶</a></dt>
<dd><p>register msg</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="cup.services.msgbroker.SystemErrmsgBroker">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.msgbroker.</span></span><span class="sig-name descname"><span class="pre">SystemErrmsgBroker</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/msgbroker.html#SystemErrmsgBroker"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.msgbroker.SystemErrmsgBroker" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.services.msgbroker.BrokerCenter" title="cup.services.msgbroker.BrokerCenter"><code class="xref py py-class docutils literal notranslate"><span class="pre">BrokerCenter</span></code></a></p>
<p>system errmsg broker, you can use it to determine whether
exiting from the system is on the way</p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.msgbroker.SystemErrmsgBroker.clean_data">
<span class="sig-name descname"><span class="pre">clean_data</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exclude_msgtypes</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/msgbroker.html#SystemErrmsgBroker.clean_data"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.msgbroker.SystemErrmsgBroker.clean_data" title="Permalink to this definition">¶</a></dt>
<dd><p>clean data of the remaining data</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.msgbroker.SystemErrmsgBroker.fatal_alert">
<span class="sig-name descname"><span class="pre">fatal_alert</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">need_stop</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/msgbroker.html#SystemErrmsgBroker.fatal_alert"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.msgbroker.SystemErrmsgBroker.fatal_alert" title="Permalink to this definition">¶</a></dt>
<dd><p>fatal alert systems</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.msgbroker.SystemErrmsgBroker.get_fatal_alerts">
<span class="sig-name descname"><span class="pre">get_fatal_alerts</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/msgbroker.html#SystemErrmsgBroker.get_fatal_alerts"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.msgbroker.SystemErrmsgBroker.get_fatal_alerts" title="Permalink to this definition">¶</a></dt>
<dd><p>get fatal alerts of the current running round</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.msgbroker.SystemErrmsgBroker.need_stop">
<span class="sig-name descname"><span class="pre">need_stop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/msgbroker.html#SystemErrmsgBroker.need_stop"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.msgbroker.SystemErrmsgBroker.need_stop" title="Permalink to this definition">¶</a></dt>
<dd><dl class="simple">
<dt>return True if the system registered on</dt><dd><p>the path needs to stop immediately</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.msgbroker.SystemErrmsgBroker.register_msg">
<span class="sig-name descname"><span class="pre">register_msg</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msgtype</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msg</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/msgbroker.html#SystemErrmsgBroker.register_msg"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.msgbroker.SystemErrmsgBroker.register_msg" title="Permalink to this definition">¶</a></dt>
<dd><p>register msg into the system</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.msgbroker.SystemErrmsgBroker.register_msgtype_callback">
<span class="sig-name descname"><span class="pre">register_msgtype_callback</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msg_type</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">callback_func</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/msgbroker.html#SystemErrmsgBroker.register_msgtype_callback"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.msgbroker.SystemErrmsgBroker.register_msgtype_callback" title="Permalink to this definition">¶</a></dt>
<dd><p>register msgtype with callback functions</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.msgbroker.SystemErrmsgBroker.register_wakeup">
<span class="sig-name descname"><span class="pre">register_wakeup</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msgtype</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">alert_cap_num</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">callfunc</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/msgbroker.html#SystemErrmsgBroker.register_wakeup"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.msgbroker.SystemErrmsgBroker.register_wakeup" title="Permalink to this definition">¶</a></dt>
<dd><p>register wakeups.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>alert_cap_num</strong> – If alert_cap_num is 0, whenever a msg of msgtype is received,
the callfunc will be called.</p></li>
<li><p><strong>msgtype</strong> – [msgbroker.FATAL|msgbroker.WARN]</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.msgbroker.SystemErrmsgBroker.warnning_alert">
<span class="sig-name descname"><span class="pre">warnning_alert</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">path</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">msg</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/msgbroker.html#SystemErrmsgBroker.warnning_alert"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.msgbroker.SystemErrmsgBroker.warnning_alert" title="Permalink to this definition">¶</a></dt>
<dd><p>warnning alert</p>
</dd></dl>

</dd></dl>

</section>
<section id="module-cup.services.serializer">
<span id="cup-services-serializer-module"></span><h2>cup.services.serializer module<a class="headerlink" href="#module-cup.services.serializer" title="Permalink to this heading">¶</a></h2>
<dl class="field-list simple">
<dt class="field-odd">description<span class="colon">:</span></dt>
<dd class="field-odd"><p>serilizers including local file serilizer</p>
</dd>
</dl>
<dl class="py class">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.serializer.</span></span><span class="sig-name descname"><span class="pre">LocalFileSerilizer</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">storage_dir</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">skip_badlog</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">max_logfile_size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1048576</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">persist_after_sec</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">600</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">BaseSerilizer</span></code></p>
<p>local file serilizer</p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.add_log">
<span class="sig-name descname"><span class="pre">add_log</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">log_type</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log_mode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log_binary</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.add_log"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.add_log" title="Permalink to this definition">¶</a></dt>
<dd><p>add log into the local file</p>
<dl class="field-list simple">
<dt class="field-odd">Returns<span class="colon">:</span></dt>
<dd class="field-odd"><p>a tuple (result_True_or_False, logid_or_None)</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.close_read">
<span class="sig-name descname"><span class="pre">close_read</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.close_read"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.close_read" title="Permalink to this definition">¶</a></dt>
<dd><p>close open4read</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.close_write">
<span class="sig-name descname"><span class="pre">close_write</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.close_write"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.close_write" title="Permalink to this definition">¶</a></dt>
<dd><p>close the writer</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.get_subdir">
<span class="sig-name descname"><span class="pre">get_subdir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">log_id</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.get_subdir"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.get_subdir" title="Permalink to this definition">¶</a></dt>
<dd><p>get log dir</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.is_empty">
<span class="sig-name descname"><span class="pre">is_empty</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.is_empty"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.is_empty" title="Permalink to this definition">¶</a></dt>
<dd><p>return if there is no log</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.is_stream_wbopen">
<span class="sig-name descname"><span class="pre">is_stream_wbopen</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.is_stream_wbopen"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.is_stream_wbopen" title="Permalink to this definition">¶</a></dt>
<dd><p>is stream open</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.open4read">
<span class="sig-name descname"><span class="pre">open4read</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.open4read"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.open4read" title="Permalink to this definition">¶</a></dt>
<dd><p>open logs for read</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.open4write">
<span class="sig-name descname"><span class="pre">open4write</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">truncate_last_failure</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.open4write"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.open4write" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Raises<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>Exception</strong> – if encounter any IOError, will raise IOError(errmsg)</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.purge_data">
<span class="sig-name descname"><span class="pre">purge_data</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">before_logid</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.purge_data"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.purge_data" title="Permalink to this definition">¶</a></dt>
<dd><p>log files which contains log (less than before_logid) will be purged.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.read">
<span class="sig-name descname"><span class="pre">read</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">record_num</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">128</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.read"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.read" title="Permalink to this definition">¶</a></dt>
<dd><p>load log into memory</p>
<dl class="field-list">
<dt class="field-odd">Notice<span class="colon">:</span></dt>
<dd class="field-odd"><p>If skip_badlog is not True, will raise IOError if the stream
encounters any error.</p>
<p>Otherwise, the stream will skip the bad log file, move to next one
and continue reading</p>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p><ol class="loweralpha simple">
<li><p>return a list of “record_num” of LogRecord.</p></li>
</ol>
<p>b. If the count number of list is less than record_num,
it means the stream encounter EOF, plz read again afterwards.</p>
<ol class="loweralpha simple" start="3">
<li><dl class="simple">
<dt>If the returned is None, it means the stream got nothing, plz</dt><dd><p>try again.</p>
</dd>
</dl>
</li>
</ol>
</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.set_current_logid">
<span class="sig-name descname"><span class="pre">set_current_logid</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">logid</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.set_current_logid"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.set_current_logid" title="Permalink to this definition">¶</a></dt>
<dd><p>reset current log id</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.set_name">
<span class="sig-name descname"><span class="pre">set_name</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.set_name"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.set_name" title="Permalink to this definition">¶</a></dt>
<dd><p>set a name of str for the serializer</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.serializer.LocalFileSerilizer.switch_logfilelist">
<span class="sig-name descname"><span class="pre">switch_logfilelist</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/serializer.html#LocalFileSerilizer.switch_logfilelist"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.serializer.LocalFileSerilizer.switch_logfilelist" title="Permalink to this definition">¶</a></dt>
<dd><p>switch logfile to logfile.old</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="cup.services.serializer.LogRecord">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.serializer.</span></span><span class="sig-name descname"><span class="pre">LogRecord</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">length</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log_id</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log_type</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log_mode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">log_binary</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#cup.services.serializer.LogRecord" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></p>
<dl class="py attribute">
<dt class="sig sig-object py" id="cup.services.serializer.LogRecord.length">
<span class="sig-name descname"><span class="pre">length</span></span><a class="headerlink" href="#cup.services.serializer.LogRecord.length" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for field number 0</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="cup.services.serializer.LogRecord.log_binary">
<span class="sig-name descname"><span class="pre">log_binary</span></span><a class="headerlink" href="#cup.services.serializer.LogRecord.log_binary" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for field number 4</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="cup.services.serializer.LogRecord.log_id">
<span class="sig-name descname"><span class="pre">log_id</span></span><a class="headerlink" href="#cup.services.serializer.LogRecord.log_id" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for field number 1</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="cup.services.serializer.LogRecord.log_mode">
<span class="sig-name descname"><span class="pre">log_mode</span></span><a class="headerlink" href="#cup.services.serializer.LogRecord.log_mode" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for field number 3</p>
</dd></dl>

<dl class="py attribute">
<dt class="sig sig-object py" id="cup.services.serializer.LogRecord.log_type">
<span class="sig-name descname"><span class="pre">log_type</span></span><a class="headerlink" href="#cup.services.serializer.LogRecord.log_type" title="Permalink to this definition">¶</a></dt>
<dd><p>Alias for field number 2</p>
</dd></dl>

</dd></dl>

</section>
<section id="module-cup.services.threadpool">
<span id="cup-services-threadpool-module"></span><h2>cup.services.threadpool module<a class="headerlink" href="#module-cup.services.threadpool" title="Permalink to this heading">¶</a></h2>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Guannan back-ported threadpool from twisted.python.
if any concern, feel free to contact Guannan (<a class="reference external" href="mailto:mythmgn&#37;&#52;&#48;gmail&#46;com">mythmgn<span>&#64;</span>gmail<span>&#46;</span>com</a>)</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<dl>
<dt>Mit License applied for twisted:</dt><dd><p><a class="reference external" href="http://www.opensource.org/licenses/mit-license.php">http://www.opensource.org/licenses/mit-license.php</a></p>
<p>Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and associated
documentation files (the “Software”),
to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
</dd>
</dl>
</div>
<dl class="py class">
<dt class="sig sig-object py" id="cup.services.threadpool.ThreadPool">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">cup.services.threadpool.</span></span><span class="sig-name descname"><span class="pre">ThreadPool</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">minthreads</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">5</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">maxthreads</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">20</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">daemon_threads</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/threadpool.html#ThreadPool"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.threadpool.ThreadPool" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Threadpool class</p>
<dl class="py method">
<dt class="sig sig-object py" id="cup.services.threadpool.ThreadPool.add_1job">
<span class="sig-name descname"><span class="pre">add_1job</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">func</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/threadpool.html#ThreadPool.add_1job"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.threadpool.ThreadPool.add_1job" title="Permalink to this definition">¶</a></dt>
<dd><p>Add one job that you want the pool to schedule.</p>
<div class="admonition caution">
<p class="admonition-title">Caution</p>
<p>Notice if you need to handle data after finishing [func], plz use
[add_1job_with_callback] which supports a [callback] option.</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>func</strong> – function that will be scheduled by the thread pool</p></li>
<li><p><strong>args</strong> – args that the [func] needs</p></li>
<li><p><strong>kw</strong> – kwargs that [func] needs</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.threadpool.ThreadPool.add_1job_with_callback">
<span class="sig-name descname"><span class="pre">add_1job_with_callback</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">result_callback</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">func</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/threadpool.html#ThreadPool.add_1job_with_callback"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.threadpool.ThreadPool.add_1job_with_callback" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>result_callback</strong> – <div class="admonition important">
<p class="admonition-title">Important</p>
<p>plz notice whether succeed or fail, the result_callback
function will be called after [func] is called.</p>
<p>function result_callback needs to accept two parameters:
(ret_in_bool, result). (True, result) will be passed to the
[func] on success. (False, result) will be passed otherwise.</p>
<p>if [func] raise any Exception, result_callback will get
(False, failure_info) as well.</p>
</div>
</p></li>
<li><p><strong>func</strong> – same to func for add_1job</p></li>
<li><p><strong>args</strong> – args for [func]</p></li>
<li><p><strong>kwargs</strong> – kwargs for [func]</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.threadpool.ThreadPool.adjust_poolsize">
<span class="sig-name descname"><span class="pre">adjust_poolsize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">minthreads</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">maxthreads</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/threadpool.html#ThreadPool.adjust_poolsize"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.threadpool.ThreadPool.adjust_poolsize" title="Permalink to this definition">¶</a></dt>
<dd><p>adjust pool size</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.threadpool.ThreadPool.dump_stats">
<span class="sig-name descname"><span class="pre">dump_stats</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">print_stdout</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/threadpool.html#ThreadPool.dump_stats"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.threadpool.ThreadPool.dump_stats" title="Permalink to this definition">¶</a></dt>
<dd><p>Dump the threadpool stat to log or stdout. Info is from class method
[get_stats]</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.threadpool.ThreadPool.get_stats">
<span class="sig-name descname"><span class="pre">get_stats</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/threadpool.html#ThreadPool.get_stats"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.threadpool.ThreadPool.get_stats" title="Permalink to this definition">¶</a></dt>
<dd><p>get threadpool running stats
waiters_num is pending thread num
working_num is working thread num
thread_num is the total size of threads</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">stat</span> <span class="o">=</span> <span class="p">{}</span>
<span class="n">stat</span><span class="p">[</span><span class="s1">&#39;queue_len&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_jobqueue</span><span class="o">.</span><span class="n">qsize</span><span class="p">()</span>
<span class="n">stat</span><span class="p">[</span><span class="s1">&#39;waiters_num&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_waiters</span><span class="p">)</span>
<span class="n">stat</span><span class="p">[</span><span class="s1">&#39;working_num&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_working</span><span class="p">)</span>
<span class="n">stat</span><span class="p">[</span><span class="s1">&#39;thread_num&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_threads</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.threadpool.ThreadPool.start">
<span class="sig-name descname"><span class="pre">start</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/threadpool.html#ThreadPool.start"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.threadpool.ThreadPool.start" title="Permalink to this definition">¶</a></dt>
<dd><p>call start before you use the threadpool</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.threadpool.ThreadPool.start1worker">
<span class="sig-name descname"><span class="pre">start1worker</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/threadpool.html#ThreadPool.start1worker"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.threadpool.ThreadPool.start1worker" title="Permalink to this definition">¶</a></dt>
<dd><p>add a thread for worker threads in the pool</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.threadpool.ThreadPool.stop">
<span class="sig-name descname"><span class="pre">stop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">force_stop</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/threadpool.html#ThreadPool.stop"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.threadpool.ThreadPool.stop" title="Permalink to this definition">¶</a></dt>
<dd><p>stop the thread pool. Notice calling this method will wait there util
all worker threads exit.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>force_stop</strong> – if force_stop is True, try to stop the threads in the pool
immediately (and this may do DAMAGE to your code logic)</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.threadpool.ThreadPool.stop1worker">
<span class="sig-name descname"><span class="pre">stop1worker</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/threadpool.html#ThreadPool.stop1worker"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.threadpool.ThreadPool.stop1worker" title="Permalink to this definition">¶</a></dt>
<dd><p>decrease one thread for the worker threads</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="cup.services.threadpool.ThreadPool.try_stop">
<span class="sig-name descname"><span class="pre">try_stop</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">check_interval</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0.1</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/services/threadpool.html#ThreadPool.try_stop"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#cup.services.threadpool.ThreadPool.try_stop" title="Permalink to this definition">¶</a></dt>
<dd><p>try to stop the threadpool.</p>
<p>If it cannot stop the pool RIGHT NOW, will NOT block.</p>
</dd></dl>

</dd></dl>

</section>
</section>


          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="index.html">cup</a></h1>








<h3>Navigation</h3>
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="cup.html">cup package</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="cup.html#subpackages">Subpackages</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="cup.net.html">cup.net package</a></li>
<li class="toctree-l3"><a class="reference internal" href="cup.res.html">cup.res package</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">cup.services package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.services.autowait">cup.services.autowait module</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.services.buffers">cup.services.buffers module</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.services.executor">cup.services.executor module</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.services.generator">cup.services.generator module</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.services.heartbeat">cup.services.heartbeat module</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.services.msgbroker">cup.services.msgbroker module</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.services.serializer">cup.services.serializer module</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.services.threadpool">cup.services.threadpool module</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="cup.shell.html">cup.shell package</a></li>
<li class="toctree-l3"><a class="reference internal" href="cup.storage.html">cup.storage package</a></li>
<li class="toctree-l3"><a class="reference internal" href="cup.util.html">cup.util package</a></li>
<li class="toctree-l3"><a class="reference internal" href="cup.web.html">cup.web package</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.cache">cup.cache module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.const">cup.const module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.decorators">cup.decorators module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.err">cup.err module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.exfile">cup.exfile module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.flag">cup.flag module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.log">cup.log module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.mail">cup.mail module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.platforms">cup.platforms module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.thread">cup.thread module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.timeplus">cup.timeplus module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.unittest">cup.unittest module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.version">cup.version module</a></li>
</ul>
</li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="index.html">Documentation overview</a><ul>
  <li><a href="cup.html">cup package</a><ul>
      <li>Previous: <a href="cup.res.html" title="previous chapter">cup.res package</a></li>
      <li>Next: <a href="cup.shell.html" title="next chapter">cup.shell package</a></li>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>document.getElementById('searchbox').style.display = "block"</script>








        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2023, CUP-DEV Team.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 7.0.1</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.13</a>
      
      |
      <a href="_sources/cup.services.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    

    
  </body>
</html>